﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using thousandclear.Data;
using thousandClear.Areas.Admin.Controllers;
using thousandClear.Util.Setting;

namespace thousandClear.Controllers
{
    public class AgentApiController : Controller
    {
        private qianjingEntities db = null;
        private AppSetting _setting = null;

        public AgentApiController()
        {

        }
        //删除功能
        [HttpGet]
        public AgentApiControllerResponse remove(int id)
        {
            AgentApiControllerResponse resp = new AgentApiControllerResponse();
            List<D_Angent> dat = new List<D_Angent>();
            List<D_Angent> csm = new List<D_Angent>();
            using (db = new qianjingEntities())
            {
                dat = db.D_Angent.Where(a => a.DATID == id || a.datDATID == id).ToList();
                foreach (var item in dat)
                {
                    item.RowStatus = 2;
                    if (item.datLevel == 2)
                    {
                        csm = db.D_Angent.Where(a => a.DATID == item.datDATID).ToList();
                        foreach (var i in csm)
                        {
                            i.RowStatus = 2;
                        }


                    }

                }
                if (dat == null)
                {
                    resp.ErrMsg = "该记录不存在";
                    return resp;
                }

                db.SaveChanges();

            }

            return resp;
        }
    }
}